<template>
  <view class="container">
    <view class="switch-container">
      <text>代叫开关</text>
      <view class="uni-list-cell uni-list-cell-pd">
        <switch :checked="isOpen" @change="toggleProxyCall"/>
      </view>
    </view>
  </view>
</template>

<script>
import {openOrCloceTaxi, getRecallStatus} from '@/api/durian/friend/friend.js';
import {getInfo} from '@/api/login.js';

export default {
  data() {
    return {
      id: undefined,
      isOpen: undefined,
      proxyCallStatus: null // 存储后端返回的状态
    };
  },
  onLoad() {
    this.selectgetRecallStatus();
  },
  methods: {
    selectgetRecallStatus() {
      getRecallStatus().then(res => {
        this.isOpen = res.data.isOpen === 0 ? true : false
      })
    },
    toggleProxyCall(e) {
      this.isOpen = e.target.value;
      this.updateProxyCallStatus(this.isOpen);
    },
    updateProxyCallStatus(status) {
      var data = {isOpen: status === true ? 0 : 1};
      // let status1 = status ? 0 : 1
      // console.log('更新状态:', status1);
      openOrCloceTaxi(data).then(res => {
        if (res.code == 200) {
          this.$modal.msgSuccess('更新成功');
          // 刷新
          getRecallStatus();
        }
      });

    }
  }
};
</script>

<style scoped>
.container {
  padding: 20px;
  margin: 10px;
  background-color: #ffffff;
  border-radius: 16px;
}

.switch-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.switch-container text {
  font-size: 16px;
}
</style>
